﻿@using WXY.Course.Model;
@model WXY.Course.Model.PageViewModel<ResourceInfo>
@{
    var paras = this.Request.Params;
    var modules = ViewData["ModuleList"] as IList<ModuleInfo>;
}
<div class="m_rtop">
    <h3>
        <label>
            内容管理
        </label>
        <span>></span>资源管理
    </h3>
</div>
<p class="m_ptop">
    <input type="button" id="btnAdd" class="btn_bg1" value="新增资源">
</p>
@using (Html.BeginForm("List", "Resource", FormMethod.Get, new { id = "searchForm" }))
{
    <div class="c_finfo">
        <p>
            <label>
                资源总数：
            </label>
            @Model.PageInfo.RecordCount
        </p>
        <p>
            <label>
                资源标题：
            </label>
            <input name="title" type="text" class="input_w"
                   value="@paras["title"]" />
        </p>

        <p>
            <label>
                资源分类：
            </label>
            <select name="categoryId">
                <option value="-1">全部</option>
                @{
    if (modules != null)
    {
        foreach (var item in modules)
        {
            <option value="@item.Code" @if (paras["categoryId"] == item.Code.ToString()) { <text> selected="selected" </text>                  }>@item.Name</option>
        }
    }
                }
            </select>
        </p>
        <p>
            <label>
                创建时间：
            </label>
            <input type="text" name="beginTime" id="beginTime"
                   value="@paras["beginTime"]" class="m_btn_date" />
            至
            <input type="text" name="endTime" id="endTime"
                   value="@paras["endTime"]" class="m_btn_date" />
        </p>
        <p class="m_btn">
            <input type="submit" class="m_sbtn" id="btnSearch" value="搜 索" />
        </p>
    </div>
}
<div class="m_box">
    <table width="980" cellpadding="0" cellspacing="0" border="1"
           class="tab1">
        <tr>
            <th width="150">操作</th>
            <th width="80">是否推荐</th>
            <th width="80">资源ID</th>
            <th width="160">资源标题</th>
            <th width="80" scope="col">所属模块</th>
            <th width="140" scope="col">创建时间</th>
            <th width="140" scope="col">更新时间</th>
        </tr>
        @if (Model.HasValue)
        {
            foreach (var item in Model.Value)
            {
                <tr>
                    <td align="center">
                        <input type="hidden" class="js_code" value="@item.Code">
                        <a href="@Url.RouteUrl("Default", new { controller = "Resource", action = "Detail", id = item.Code })">查看</a>
                        <a href="@Url.Action("Edit", "Resource", new { Id = item.Code })" name="editLink">编辑</a>
                        <a href="javascript:void(0)" name="deleteLink" data-href="@Url.Action("Delete","Resource")">删除</a>
                        @if (!item.IsRecommended)
                        {
                            <a href="javascript:void(0)" name="recommendLink" data-href="@Url.Action("Recommend","Resource")">推荐</a>
                        }
                    </td>
                    <td align="center">@item.IsRecommended</td>
                    <td align="center">@item.Code</td>
                    <td>@item.Title</td>
                    <td>@(item.ModuleInfo == null ? "未知模块" : item.ModuleInfo.Name)</td>
                    <td>@item.CreateTime</td>
                    <td>@item.UpdateTime</td>
                </tr>
            }
        }
        else
        {
            <tr>
                <td colspan="6" style="text-align:center;">@(string.IsNullOrEmpty(Model.Message) ? "暂无数据" : Model.Message)</td>
            </tr>
        }
    </table>
    <div class="page">
        @Html.PageBar(Model.PageInfo, 10)
    </div>
</div>

<script type="text/javascript">
    $(function () {
        $('input.m_btn_date').on('click', function () {
            WdatePicker();
        });
        $("#btnAdd").on("click", function () {
            location.href = "@Url.Action("Edit", "Resource")";
        });
        $("a[name='deleteLink'],a[name='recommendLink']").on("click", function () {
            doAction(this);
        });

        function doAction(e) {
            art.dialog({
                lock: true,
                title: '提示',
                content: '确定要' + $(e).html() + '该资源么？',
                button: [
                    {
                        value: '确定',
                        callback: function () {
                            var id = $(e).parent().find("input.js_code").val();
                            $.ajax({
                                type: 'post',
                                url: $(e).attr("data-href"),
                                data: { id: id },
                                success: function (data) {
                                    if (data.IsSuccess && data.Data > 0) {
                                        art.dialog({
                                            lock: true,
                                            title: '提示',
                                            content: $(e).html() + '成功',
                                            ok: function () { location.reload(); }
                                        });
                                    } else {
                                        art.dialog({
                                            lock: true,
                                            title: '提示',
                                            content: $(e).html() + "失败" + data.Message,
                                            ok: function () {
                                                this.close();
                                            }
                                        });
                                    }
                                }
                            });
                        }
                    },
                    {
                        value: '取消',
                        focus: true,
                        callback: function () {
                            this.close();
                        }
                    }
                ]
            });
        }
    });
</script>
